<?php
/**
 * The template for displaying posts in the Gallery Post Format on index and archive pages
 *
 * Learn more: http://codex.wordpress.org/Post_Formats
 *
 * @package WordPress
 * @subpackage Freshine
 * @since Freshine 1.1.0
 */
?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<div class="entry-date">
		<span class="month"><?php echo get_the_date('M'); ?></span>
		<span class="day"><?php echo get_the_date('d'); ?></span>
	</div>
	<h2 class="entry-format"><?php _e( 'Gallery', 'f9vn' ); ?></h2>
<?php if( is_single() ): ?>
	<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'f9vn' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php else : ?>
	<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'f9vn' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php endif; ?>

	<?php if ( is_search() ) : // Only display Excerpts for search pages ?>
		<div class="entry-summary">
			<?php the_excerpt(); ?>
		</div><!-- .entry-summary -->
		<?php else : ?>
		<div class="entry-content">
			<?php if ( post_password_required() ) : ?>
				<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>

			<?php else : ?>
				<?php
					$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
					if ( $images ) :
						$total_images = count( $images );
						$i=0;
						foreach ( $images as $attachment_id => $attachment ) {
						$image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' );
						?>
						<div class="gallery-thumb<?php if($i==0) echo " first";?>">
							<a href="<?php the_permalink(); ?>" style="background-image: url('<?php echo $image_attributes[0] ?>');">
							<?php echo basename($image_attributes[0]); ?>
							</a><!-- .gallery-thumb -->
						</div>
						<?php
						if($i==2) break;
						$i++;
						} ?>

				<p><em><?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyeleven' ),
						'href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
						number_format_i18n( $total_images )
					); ?></em></p>
			<?php endif; ?>
			<?php the_excerpt(); ?>
		<?php endif; ?>
		
	</div><!-- .entry-content -->
		<div class="entry-utility">
			<?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<div class="edit-link">', '</div>' ); ?>
		</div><!-- .entry-utility -->
	<?php endif; ?>
	
	
</div><!-- #post-<?php the_ID(); ?> -->
